import React, { Component } from "react";
import service from "../../service";

class Reg extends Component {
  state = {
    user: "123",
    pass: "123",
  };
  onReg = async () => {
    // console.log(111);
    console.log(this.state.user)
    console.log(this.state.pass)
    console.log(service.Register);
    const res = (await service.Reg(this.state.user, this.state.pass))||{};
    console.log(res);
    if (res.codo === 0) {
      console.log("注册成功");
      alert("恭喜您，注册成功！");
      alert("去登录");
      // this.$router.replace("/login")
    } else {
      console.log("注册失败");
      alert("注册失败");
    }
    
  };
  render() {
    const { user, pass } = this.state;
    return (
      <div className="Register">
        <form className="form">
          <div className="formItem">
            <label htmlFor="username">用户名：</label>
            <input
              type="text"
              id="username"
              value={user}
              onChange={(e) => {
                this.setState({ user: e.target.value });
              }}
            />
          </div>
          <div className="formItem">
            <label htmlFor="password">密码：</label>
            <input
              type="password"
              id="password"
              value={pass}
              onChange={(e) => {
                this.setState({ pass: e.target.value });
              }}
            />
          </div>
          <div className="RegisterBtn">
            <button className="Register" onClick={this.onReg}>
              注册
            </button>
          </div>
        </form>
      </div>
    );
  }
}

export default Reg;